<template>
  <div class="left-bottom-cmp">
    <div class="chart-name">
      Twitter NPL Trend
      <dv-decoration-3 style="width: 200px; height: 20px" />
    </div>
    <dv-charts :option="option" />
  </div>
</template>

<script>
export default {
  name: "LeftBottomCmp",
  data() {
    return {
      option: {
        legend: {
          data: [
            {
              name: "Positive",
              // color: "#ff5ca9",
            },
            {
              name: "Negative",
              // color: "#3de7c9",
            },
            {
              name: "Netural",
              // color: "#f5d94e",
            },
          ],
          textStyle: { fill: "#fff" },
        },
        xAxis: {
          data: [],
          axisLine: {
            style: {
              stroke: "#999",
            },
          },
          axisLabel: {
            style: {
              fill: "#999",
            },
          },
          axisTick: {
            show: false,
          },
        },
        yAxis: {
          data: "value",
          splitLine: {
            show: false,
          },
          axisLine: {
            style: {
              stroke: "#999",
            },
          },
          axisLabel: {
            style: {
              fill: "#999",
            },
          },
          axisTick: {
            show: false,
          },
          min: null,
          max: null,
        },
        series: [],
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      let mydata = this;
      mydata
        .$axios({
          method: "get",
          url: "http://116.62.228.138:10003/media/twitterTrendGet",
        })
        .then((res) => {
          let getxAxis = [];
          let getSeries_p = [];
          let getSeries_n = [];
          let getSeries_m = [];
          let getmax = 0;
          let getmin = Number.MAX_VALUE;
          res.data.data.map((item) => {
            getxAxis.push(item.date);
            getSeries_p.push(item.positive);
            getSeries_n.push(item.negative);
            getSeries_m.push(item.neutral);
            if (item.positive > getmax) getmax = item.positive;
            else if (item.positive < getmin) getmin = item.positive;
            if (item.negative > getmax) getmax = item.negative;
            else if (item.negative < getmin) getmin = item.negative;
            if (item.neutral > getmax) getmax = item.neutral;
            else if (item.neutral < getmin) getmin = item.neutral;
          });
          console.log(getmax);
          this.option.xAxis.data = getxAxis;
          this.option.series = [
            {
              name: "Positive",
              data: getSeries_p,
              type: "bar",
              // lineStyle: {
              //   stroke: "#ff5ca9",
              // },
              // linePoint: {
              //   radius: 4,
              //   style: {
              //     fill: "#ff5ca9",
              //     stroke: "transparent",
              //   },
              // },
            },
            {
              name: "Negative",
              data: getSeries_n,
              type: "bar",
              // smooth: true,
              // lineArea: {
              //   show: true,
              //   gradient: ["rgba(55, 162, 218, 0.6)", "rgba(55, 162, 218, 0)"],
              // },
              // lineStyle: {
              //   lineDash: [5, 5],
              // },
              // linePoint: {
              //   radius: 4,
              //   style: {
              //     fill: "#00db95",
              //   },
              // },
            },
            {
              data: getSeries_m,
              type: "bar",
              name: "Netural",
              // lineArea: {
              //   show: true,
              //   gradient: [
              //     "rgba(245, 217, 79, 0.8)",
              //     "rgba(245, 217, 79, 0.2)",
              //   ],
              // },
              // lineStyle: {
              //   stroke: "#f5d94e",
              // },
              // linePoint: {
              //   radius: 4,
              //   style: {
              //     fill: "#f5d94e",
              //     stroke: "transparent",
              //   },
              // },
            },
          ];
          this.option.yAxis.min = getmin;
          this.option.yAxis.max = getmax;
        });
    },
  },
};
</script>

<style lang="less">
.left-bottom-cmp {
  position: relative;
  padding: 0 50px;
  box-sizing: border-box;

  .chart-name {
    position: absolute;
    right: 70px;
    text-align: right;
    font-size: 20px;
    top: 10px;
  }
}
</style>
